package com.example.shop.order.dao;

import com.example.shop.order.dto.OrderDetailInfo;
import com.example.shop.order.typehandler.OrderStateTypeHandler;
import com.example.shop.order.typehandler.PaymentMethodTypeHandler;
import org.apache.ibatis.annotations.*;

@Mapper
public interface OrderDetailInfoDao {

    @Results(id = "OrderDetailInfoResultMap",value = {
        @Result(column = "goods_id",property = "goodsInfo",
                one = @One(select = "com.example.shop.order.dao.OrderGoodsInfoDao.selectById")),
        @Result(column = "order_state",property = "orderState",typeHandler = OrderStateTypeHandler.class),
        @Result(column = "payment_method",property = "paymentMethod",typeHandler = PaymentMethodTypeHandler.class),
        @Result(column = "courier_id",property = "courier",
                one = @One(select = "com.example.shop.mapper.CourierMapper.selectById"))
    })
    @Select("select order_id,user_id,goods_id,courier_id,transaction_id,order_time,delivery_time,payment_method" +
            "order_state,user_purchased_goods_class,user_purchased_number,user_buy_time,real_pay " +
            "from `order` " +
            "where user_id = ${userId} and order_id = ${orderId}")
    OrderDetailInfo selectById(@Param("userId") long userId,@Param("orderId") long orderId);

    @ResultMap("OrderDetailInfoResultMap")
    @Select("select o.order_id,o.user_id,o.goods_id,o.courier_id,o.transaction_id,o.order_time,o.delivery_time,o.payment_method" +
            "o.order_state,o.user_purchased_goods_class,o.user_purchased_number,o.user_buy_time,real_pay " +
            "from `order` o join goods g on o.goods_id = g.goods_id " +
            "where g.merchant_id = ${merchantId} and order_id = ${orderId}")
    OrderDetailInfo selectMerchantOrderById(@Param("merchantId")long merchantId,@Param("orderId") long orderId);
}
